package tt.dz.appserver.service.avro.server;

import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.avro.AvroRemoteException;
import org.apache.log4j.Logger;
import org.springframework.cache.annotation.CacheEvict;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import tt.dz.appserver.dao.ext.ChargerReserveDao;
import tt.dz.appserver.dao.ext.UserInfoDao;
import tt.dz.appserver.entity.dto.oms.ChargeResultNotifyDto;
import tt.dz.appserver.entity.dto.oms.ExceptionNotifyDto;
import tt.dz.appserver.entity.dto.oms.OrderNotifyDto;
import tt.dz.appserver.entity.dto.oms.ReservationNotifyDto;
import tt.dz.appserver.entity.dto.oms.StationUpdateNotifyDto;
import tt.dz.appserver.entity.dto.push.ChargeDto;
import tt.dz.appserver.entity.dto.push.ErrorDto;
import tt.dz.appserver.entity.dto.push.OrderDto;
import tt.dz.appserver.entity.dto.push.ReservationDto;
import tt.dz.appserver.entity.model.user.UserInfo;
import tt.dz.appserver.entity.vo.station.StationInfoVo;
import tt.dz.appserver.service.avro.client.oms.dzttOmsServiceProtocol;
import tt.dz.appserver.service.business.UserInfoService;
import tt.dz.appserver.util.CodeUtils;
import tt.dz.appserver.util.Constants;
import tt.dz.appserver.util.JpushUtils;
import tt.dz.appserver.util.ReflectUtils;
import tt.dz.appserver.util.StationOpUtils;
import tt.dz.appserver.util.StringUtils;
import tt.dz.appserver.util.WebSocketUtils;
import tt.dz.appserver.util.date.DateUtil;
import tt.dz.appserver.util.dzcode.OmsCode;
import tt.dz.appserver.util.enums.Response;
import tt.dz.appserver.util.enums.push.ChargePushType;
import tt.dz.appserver.util.enums.push.ChargeType;
import tt.dz.appserver.util.enums.push.ErrorPushType;
import tt.dz.appserver.util.enums.push.PushBusinessCode;
import tt.dz.appserver.util.enums.push.ReservationPushType;

/**
 * rpc接口
 * 
 * @author xie
 *
 */
public class RpcAppServiceImpl implements RpcAppService {

	private static final String SUCCESS = "success";
	private static final String FAIL = "fail";
	private static final Logger LOG = Logger.getLogger("[AppServer 服务器 OMS接口]:");

	/** oms 调用接口 */
	@Resource(name = "omsMessageProtocolRequestor")
	private dzttOmsServiceProtocol omsService;

	/** 预约操作Dao */
	@Resource
	private ChargerReserveDao reservationDao;

	/** 用户操作Dao */
	@Resource
	private UserInfoDao userInfoDao;

	/** 用户业务接口 */
	@Resource
	private UserInfoService userInfoService;

	/**
	 * 通知ＡＳ站点数据更新
	 */

	@CacheEvict(value = "station", allEntries = true)
	@Override
	public CharSequence stationUpdateNotify(CharSequence params) throws AvroRemoteException {

		LOG.info("OMS通知我,站点需要更新了.....");

		// 获取参数
		StationUpdateNotifyDto stationUpdateNotifyDto = JSONObject.parseObject(params.toString(),
				StationUpdateNotifyDto.class);

		LOG.info("开始更新此省份的数据【" + stationUpdateNotifyDto.getProvinceId() + "】.....");

		String provinceCode = stationUpdateNotifyDto.getProvinceId();
		// 调用更改接口
		String resultJsonString = omsService.updateMapDataPackage(provinceCode).toString();

		// 获取更新之后的数据
		JSONObject omsResultObject = JSONObject.parseObject(resultJsonString);

		LOG.info("此省份的数据【" + stationUpdateNotifyDto.getProvinceId() + "】为:" + omsResultObject);

		String code = omsResultObject.getString(Constants.OmsServerResultField.CODE);

		if (OmsCode.SUCCESS.equals(code)) {

			// 删除该省份电站
			StationOpUtils.deleteProvinceStation(provinceCode);

			LOG.info("更新成功,正在写入中.....");
			// 获取电站原始列表
			JSONArray stationArray = omsResultObject.getJSONArray("list");
			// 列表大小
			int stationArraySize = stationArray.size();

			// 得到当前的站点
			JSONObject stationObject = null;

			// 遍历大小
			for (int i = 0; i < stationArraySize; i++) {

				stationObject = stationArray.getJSONObject(i);

				String stationId = stationObject.getString("station_id");
				String stationName = stationObject.getString("station_name");
				String operMerchantId = stationObject.getString("oper_merchant_id");
				String provinceId = stationObject.getString("province_code");
				String districtCode = stationObject.getString("district_code");
				String districtName = stationObject.getString("district_name");
				String parkingType = stationObject.getString("parking_type");
				String totalCharger = stationObject.getString("total_charger");
				String stationType = stationObject.getString("station_type");
				String address = stationObject.getString("address");
				String currentState = stationObject.getString("current_state");
				String directNum = stationObject.getString("direct_num");
				String alternateNum = stationObject.getString("alternate_num");
				String telNo = stationObject.getString("tel_no");
				String reviewState = stationObject.getString("review_state");
				String reviewText = stationObject.getString("review_text");
				String chargePortType = stationObject.getString("charge_port_type");
				String score = stationObject.getString("score");

				// 封装站点字段
				StationInfoVo stationDetailVo = new StationInfoVo();
				stationDetailVo.setStationId(stationId);// 站点ID
				stationDetailVo.setStationName(stationName);// 名称
				stationDetailVo.setOperMerchantId(operMerchantId);// 充电运营服务商ID
				stationDetailVo.setDistrictCode(districtCode);// 区县代码
				stationDetailVo.setDistrictName(districtName);// 区县名称
				stationDetailVo.setParkingType(parkingType);// 停车处：1，停车楼 2，室外
															// 3，地下室
				stationDetailVo.setTotalCharger(totalCharger);// 总电桩数量
				stationDetailVo.setStationType(stationType);// 站点类型 1直流2交流3混合

				if ("3".equals(reviewState)) {
					stationDetailVo.setBooking("1");// 是否可预约 1可以 0不可以
				} else {
					stationDetailVo.setBooking("0");// 是否可预约 1可以 0不可以
				}

				stationDetailVo.setAddress(address);// 详细地址
				stationDetailVo.setCurrentState(currentState);// 状态 1运营总 2安装中
				stationDetailVo.setDirectNum(directNum);// 直流数量
				stationDetailVo.setAlternateNum(alternateNum);// 交流数量
				stationDetailVo.setTelNo(telNo);// 自营电话
				stationDetailVo.setReviewState(reviewState);// 审核状态
				stationDetailVo.setReviewText(reviewText);// 审核描述，说明

				// 位置信息列表
				JSONArray locations = stationObject.getJSONArray("locationList");
				if (locations.size() > 0) {
					String latitude = locations.getJSONObject(0).getString("coordinate_y");
					String longitude = locations.getJSONObject(0).getString("coordinate_x");
					stationDetailVo.setLongitude(longitude);
					stationDetailVo.setLatitude(latitude);
				}

				stationDetailVo.setProvinceId(provinceId);// 省份ID
				stationDetailVo.setChargePortType(chargePortType);
				stationDetailVo.setScore(score);

				// 新写入文件
				StationOpUtils.writeOrUpdateStationObject(provinceId, stationName, stationDetailVo);
			}

			// 将封装后的集合加入需要返回的json对象中
			// 获取更新第三方站点
			LOG.info("信息：开始获取第三方站点数据.................................." + DateUtil.getDateTime());

			// 调用查询接口
			String thirdResultJsonString = omsService.getExternalStation(provinceCode).toString();
			// 数据转换为json
			JSONObject thirdOmsResultObject = JSONObject.parseObject(thirdResultJsonString);

			// 获取返回代码
			code = thirdOmsResultObject.getString(Constants.OmsServerResultField.CODE);
			if (OmsCode.SUCCESS.equals(code)) {

				// 获取电站原始列表
				JSONArray thirdStationArray = thirdOmsResultObject.getJSONArray("list");
				// 列表大小
				stationArraySize = thirdStationArray.size();

				// 得到当前的站点
				JSONObject thirdStationObject = null;

				LOG.info("信息：正在写入站点数据.................................." + DateUtil.getDateTime());
				// 遍历大小
				for (int i = 0; i < stationArraySize; i++) {

					// 获取的对象
					thirdStationObject = thirdStationArray.getJSONObject(i);
					// 需要写入的对象
					StationInfoVo stationDetailVo = new StationInfoVo();

					String stationId = thirdStationObject.getString("station_id");
					String stationName = thirdStationObject.getString("station_name");
					String operMerchantId = thirdStationObject.getString("oper_merchant_id");
					String districtCode = thirdStationObject.getString("district_code");
					String districtName = thirdStationObject.getString("district_name");
					String parkingType = thirdStationObject.getString("parking_type");
					String totalCharger = thirdStationObject.getString("total_charger");
					String stationType = thirdStationObject.getString("station_type");
					String address = thirdStationObject.getString("address");
					String currentState = thirdStationObject.getString("current_state");
					String directNum = thirdStationObject.getString("direct_num");
					String alternateNum = thirdStationObject.getString("alternate_num");
					String telNo = thirdStationObject.getString("tel_no");
					String provinceId = thirdStationObject.getString("province_code");
					String chargePortType = thirdStationObject.getString("charge_port_type");

					// 位置信息列表
					JSONArray locations = thirdStationObject.getJSONArray("locationList");
					if (locations.size() > 0) {
						String latitude = locations.getJSONObject(0).getString("coordinate_y");
						String longitude = locations.getJSONObject(0).getString("coordinate_x");
						stationDetailVo.setLongitude(longitude);
						stationDetailVo.setLatitude(latitude);
					}

					String score = stationObject.getString("score");

					// 封装站点字段
					stationDetailVo.setStationId(stationId);// 站点ID
					stationDetailVo.setStationName(stationName);// 名称
					stationDetailVo.setOperMerchantId(operMerchantId);// 充电运营服务商ID
					stationDetailVo.setDistrictCode(districtCode);// 区县代码
					stationDetailVo.setDistrictName(districtName);// 区县名称
					stationDetailVo.setParkingType(parkingType);// 停车处：1，停车楼
																// 2，室外 3，地下室
					stationDetailVo.setTotalCharger(totalCharger);// 总电桩数量
					stationDetailVo.setStationType(stationType);// 站点类型
																// 1直流2交流3混合
					stationDetailVo.setAddress(address);// 详细地址
					stationDetailVo.setCurrentState(currentState);// 状态 1运营总
																	// 2安装中 3规划中
					stationDetailVo.setDirectNum(directNum);// 直流数量
					stationDetailVo.setAlternateNum(alternateNum);// 交流数量
					stationDetailVo.setTelNo(telNo);// 自营电话
					stationDetailVo.setProvinceId(provinceId);// 省份ID

					stationDetailVo.setBooking("0");// 是否可预约 1可以 0不可以

					stationDetailVo.setChargePortType(chargePortType);// 充电接口类型：1.国标；2特斯拉；
																		// 3.ABB，
																		// 4其他

					stationDetailVo.setScore(score);

					// 将对象写入文件
					StationOpUtils.writeOrUpdateStationObject(provinceId, stationName, stationDetailVo);
				}
				if (stationArraySize == 0) {
					LOG.error("信息：并无任何站点数据.................................." + DateUtil.getDateTime());
				} else {
					LOG.info("信息：站点数据写入结束.................................." + DateUtil.getDateTime());
				}
			} else {
				LOG.error("信息：站点数据获取出错   错误代码为：" + code + "     " + DateUtil.getDateTime());
			}

			LOG.info("该站点更新结束.....");
			return SUCCESS;
		} else {
			return FAIL;
		}
	}

	/**
	 * 预约状态包含以下情况
	 * 
	 * -1用户已取消 0正在预约 1预约成功 2正在取消 3充电中 4充电结束
	 */
	@Override
	public CharSequence reservationNotify(CharSequence params) throws AvroRemoteException {

		ReservationNotifyDto reservationNotifyDto = JSONObject.parseObject(params.toString(),
				ReservationNotifyDto.class);

		String plugNo = reservationNotifyDto.getPlugNo();
		String chargerId = reservationNotifyDto.getChargerId();
		String serialNo = reservationNotifyDto.getSerialNo();
		String stationName = reservationNotifyDto.getStationName();
		String startTime = reservationNotifyDto.getStartTime();
		String reservationSn = reservationNotifyDto.getReservationSn();// 预约流水号
		String userCard = reservationNotifyDto.getUserCard();

		LOG.info("OMS通知AS服务器预约状态,通知动作为:【" + reservationNotifyDto.getAction() + "】 通知桩地址为:【" + chargerId + "】 用户卡号为:【"
				+ userCard + "】 站点为:【" + stationName + "】 桩编号为:【" + serialNo + "】 预约流水号为:【" + reservationSn + "】");

		String message = "";
		// 推送对象
		ReservationDto reservationDto = new ReservationDto();
		switch (reservationNotifyDto.getAction()) {

		// 如果为预约
		case "reservation":
			reservationDto.setActionType(ReservationPushType.RESERVATION.getCode());
			message = "您已经预约:" + stationName + "下的" + serialNo + "号电桩 第" + plugNo + "充电插口";
			break;

		// 若果为取消预约
		case "cancelReservation":
			reservationDto.setActionType(ReservationPushType.CANCEL_RESERVATION.getCode());
			message = "您在 " + startTime + "预约的" + stationName + "下的" + serialNo + "号电桩的第" + plugNo + "充电插口已经取消";
			break;
		// 超时自动取消
		case "timeOut":
			reservationDto.setActionType(ReservationPushType.TIMEOUT.getCode());
			message = "您在 " + startTime + "预约的" + stationName + "下的" + serialNo + "号电桩的第" + plugNo + "充电插口 超过最大时间已自动取消";
			break;
		default:
			break;
		}
		String userId = userInfoService.getUserIdByUserCard(userCard);
		// if (userId.length() < 20) {
		// LOG.error("预约通知接口,通过主服务器获取用户ID发生错误,卡号为:【" + userCard + "】错误码为" +
		// userId);
		// return FAIL;
		// }
		LOG.info("通过主服务器查询此 【" + userCard + "】 卡的userId成功,id为 【" + userId + "】");
		UserInfo userInfo = userInfoDao.findUserByUserId(userId);

		reservationDto.setChargerId(chargerId);
		reservationDto.setPlugNo(plugNo);
		reservationDto.setReservationSn(reservationSn);
		try {
			Map<String, String> pushData = ReflectUtils.objectParseMap(reservationDto);
			Map<String, String> pushMap = new HashMap<String, String>();
			pushMap.put("action", PushBusinessCode.RESERVATION.getCode());
			pushMap.put("data", JSON.toJSONString(pushData));
			// 在此调用获取渠道还是app ,通过userID pengyu add 同一个手机号码通过不同渠道对应的UERID不同
			boolean isScoket = WebSocketUtils.hasConnection(userId);
			if (isScoket) {
				LOG.info("websocket--------预约推送给此用户userid 【" + userInfo.getUser_id() + "】");
				WebSocketUtils.sendMessage(userId, JSON.toJSONString(pushMap));
			} else {
				LOG.info("极光---------预约推送给此用户 【" + userInfo.getJpush_id() + "】");
				if (StringUtils.isNotBlank(userInfo.getJpush_id()))
					JpushUtils.pushMsgByRegId(userInfo.getJpush_id(), message, pushMap);
			}

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return FAIL;
		}
	}

	@Override
	public CharSequence orderNotify(CharSequence params) throws AvroRemoteException {

		OrderNotifyDto orderNotifyDto = JSONObject.parseObject(params.toString(), OrderNotifyDto.class);

		String orderNo = orderNotifyDto.getOrderNo();
		String money = orderNotifyDto.getMoney();
		String userCard = orderNotifyDto.getUserCard();

		LOG.info("OMS通知AS服务器订单状态, 用户卡号为:【" + userCard + "】 订单号码为:【" + orderNo + "】");

		OrderDto dto = new OrderDto();
		dto.setMoney(money);
		dto.setOrderNo(orderNo);
		String userId = userInfoService.getUserIdByUserCard(userCard);
		// if (userId.length() < 20) {
		// LOG.error("订单通知接口,通过主服务器获取用户ID发生错误,卡号为:【" + userCard + "】错误码为【" +
		// userId + "】");
		// return FAIL;
		// }
		LOG.info("通过主服务器查询此 【" + userCard + "】 卡的userId成功,id为 【" + userId + "】");
		UserInfo userInfo = userInfoDao.findUserByUserId(userId);

		try {
			Map<String, String> pushData = ReflectUtils.objectParseMap(dto);
			Map<String, String> pushMap = new HashMap<String, String>();
			pushMap.put("action", PushBusinessCode.ORDER.getCode());
			pushMap.put("data", JSON.toJSONString(pushData));

			NumberFormat nf = NumberFormat.getNumberInstance();
			nf.setMaximumFractionDigits(2);
			String moneyStr = nf.format(Double.parseDouble(money));
			String message = "您有一笔订单未支付,金额为:" + moneyStr;

			// 在此调用获取渠道还是app ,通过userID
			boolean isScoket = WebSocketUtils.hasConnection(userId);
			if (isScoket) {
				LOG.info("websocket------订单推送给此用户userid 【" + userInfo.getUser_id() + "】");
				WebSocketUtils.sendMessage(userId, JSON.toJSONString(pushMap));
			} else {
				LOG.info("极光----------订单推送给此用户【 " + userInfo.getJpush_id() + "】");
				if (StringUtils.isNotBlank(userInfo.getJpush_id()))
					JpushUtils.pushMsgByRegId(userInfo.getJpush_id(), message, pushMap);
			}

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return FAIL;
		}
	}

	@Override
	public CharSequence exceptionNotify(CharSequence params) throws AvroRemoteException {

		ExceptionNotifyDto exceptionNotifyDto = JSONObject.parseObject(params.toString(), ExceptionNotifyDto.class);

		String code = exceptionNotifyDto.getResponseCode();
		String stationName = exceptionNotifyDto.getStationName();
		String startTime = exceptionNotifyDto.getStartTime();
		String serialNo = exceptionNotifyDto.getSerialNo();

		// 获取获取信息
		Response response = CodeUtils.getCodeByOMSServerCode(code);
		String userCard = exceptionNotifyDto.getUserCard();

		LOG.info("OMS通知AS服务器异常状态,通知动作为:【" + exceptionNotifyDto.getAction() + "】 用户卡号为:【" + userCard + "】 站点为:【"
				+ stationName + "】 桩编号为:【" + serialNo + "】");

		String message = "";

		ErrorDto dto = new ErrorDto();

		switch (exceptionNotifyDto.getAction()) {

		// 如果为充电
		case "charge":
			dto.setActionType(ErrorPushType.OPEN_CHARGE.getCode());
			message = "您在 " + startTime + " 开启的" + stationName + "下的" + serialNo + "号电桩发生异常,具体原因是:" + response.getMsg();
			break;

		// 若果为结束充电
		case "endCharge":
			dto.setActionType(ErrorPushType.CLOSE_CHARGE.getCode());
			message = "您在 " + startTime + " 关闭的" + stationName + "下的" + serialNo + "号电桩发生异常,具体原因是:" + response.getMsg();
			break;

		// 预约
		case "reservation":
			dto.setActionType(ErrorPushType.RESERVATION.getCode());
			message = "您在 " + startTime + " 预约的" + stationName + "下的" + serialNo + "号电桩发生异常,具体原因是:" + response.getMsg();
			break;

		// 取消预约
		case "cancelReservation":
			dto.setActionType(ErrorPushType.CANCEL_RESERVATION.getCode());
			message = "您在 " + startTime + " 取消" + stationName + "下的" + serialNo + "号电桩的预约发生异常,具体原因是:"
					+ response.getMsg();
			break;
		default:
			break;
		}

		String userId = userInfoService.getUserIdByUserCard(userCard);

		// 在此调用获取渠道还是app ,通过userID
		boolean isScoket = WebSocketUtils.hasConnection(userId);

		// if (userId.length() < 20) {
		// LOG.error("异常通知接口,通过主服务器获取用户ID发生错误,卡号为:【" + userCard + "】错误码为【" +
		// userId + "】");
		// return FAIL;
		// }
		LOG.info("通过主服务器查询此 【" + userCard + "】 卡的userId成功,id为 【" + userId + "】");

		UserInfo userInfo = userInfoDao.findUserByUserId(userId);
		dto.setErrorCode(response.getCode());
		dto.setErrorMsg(response.getMsg());
		try {

			Map<String, String> pushData = ReflectUtils.objectParseMap(dto);
			Map<String, String> pushMap = new HashMap<String, String>();
			pushMap.put("action", PushBusinessCode.EXCEPTION.getCode());
			pushMap.put("data", JSON.toJSONString(pushData));
			if (isScoket) {
				LOG.info("websocket-----异常推送给此用户userid 【" + userInfo.getUser_id() + "】");
				WebSocketUtils.sendMessage(userId, JSON.toJSONString(pushMap));
			} else {
				LOG.info("极光----------异常推送给此用户 【" + userInfo.getJpush_id() + "】");
				if (StringUtils.isNotBlank(userInfo.getJpush_id()))
					JpushUtils.pushMsgByRegId(userInfo.getJpush_id(), message, pushMap);
			}

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return FAIL;
		}
	}

	@Override
	public CharSequence chargeNotify(CharSequence params) throws AvroRemoteException {

		ChargeResultNotifyDto chargeResultNotifyDto = JSONObject.parseObject(params.toString(),
				ChargeResultNotifyDto.class);

		// 获取桩号(地址)
		String serialNo = chargeResultNotifyDto.getSerialNo();
		String stationName = chargeResultNotifyDto.getStationName();
		String plugNo = chargeResultNotifyDto.getPlugNo();
		String startTime = chargeResultNotifyDto.getStartTime();
		String chargerId = chargeResultNotifyDto.getChargerId();
		String chargeSn = chargeResultNotifyDto.getChargeSn();
		String userCard = chargeResultNotifyDto.getUserCard();

		String userId = userInfoService.getUserIdByUserCard(userCard);
		// 在此调用获取渠道还是app ,通过userID
		boolean isScoket = WebSocketUtils.hasConnection(userId);

		LOG.info("OMS通知AS服务器充电状态,通知充电类型为:【 " + chargeResultNotifyDto.getChargeType() + " 】通知动作为:【"
				+ chargeResultNotifyDto.getAction() + "】 通知桩地址为:【" + chargerId + "】 用户卡号为:【" + userCard + "】 站点为:【"
				+ stationName + "】 桩编号为:【" + serialNo + "】 充电流水号为:【" + chargeSn + "】");

		String message = "";

		ChargeDto dto = new ChargeDto();
		// 扫码充电
		if (ChargeType.SCAN_CHARGE.getCode().equals(chargeResultNotifyDto.getChargeType())) {

			message = "您于 " + startTime + " 扫码成功开启 " + stationName + serialNo + "号电桩 第" + plugNo + "插头充电";

			switch (chargeResultNotifyDto.getAction()) {

			// 如果为充电
			case "charge":
				dto.setActionType(ChargePushType.OPEN_CHARGE.getCode());
				message = "您于 " + startTime + " 扫码成功开启 " + stationName + serialNo + "号电桩 第" + plugNo + "插头充电";
				break;

			// 若果为结束充电
			case "endCharge":
				dto.setActionType(ChargePushType.CLOSE_CHARGE.getCode());
				message = "您于 " + startTime + " 成功关闭 " + stationName + serialNo + "号电桩 第" + plugNo + "插头扫码充电";
				break;
			default:
				break;
			}

		}
		// 预约充电
		else if (ChargeType.RESERVATION_CHARGE.getCode().equals(chargeResultNotifyDto.getChargeType())) {

			switch (chargeResultNotifyDto.getAction()) {

			// 如果为充电
			case "charge":
				dto.setActionType(ChargePushType.OPEN_CHARGE.getCode());
				message = "您于 " + startTime + " 成功开启 " + stationName + serialNo + "号电桩 第" + plugNo + "插头充电";
				break;

			// 若果为结束充电
			case "endCharge":
				dto.setActionType(ChargePushType.CLOSE_CHARGE.getCode());
				message = "您于 " + startTime + " 成功关闭 " + stationName + serialNo + "号电桩 第" + plugNo + "插头充电";
				break;
			default:
				break;
			}
		}

		// if (userId.length() < 20) {
		// LOG.error("充电通知接口,通过主服务器获取用户ID发生错误,卡号为:【" + userCard + "】错误码为【" +
		// userId + "】");
		// return FAIL;
		// }

		LOG.info("通过主服务器查询此 【" + userCard + "】 卡的userId成功,id为【" + userId + "】");

		UserInfo userInfo = userInfoDao.findUserByUserId(userId);
		dto.setChargerId(chargerId);
		dto.setChargeSn(chargeSn);
		dto.setPlugNo(plugNo);
		try {
			// 根据不同渠道，确认采用是激光推送还是websocket推送

			Map<String, String> pushData = ReflectUtils.objectParseMap(dto);
			Map<String, String> pushMap = new HashMap<String, String>();
			pushMap.put("action", PushBusinessCode.CHARGE.getCode());
			pushMap.put("data", JSON.toJSONString(pushData));

			if (isScoket) {
				LOG.info("websocket------充电推送给此用户userid 【" + userInfo.getUser_id() + "】");
				WebSocketUtils.sendMessage(userId, JSON.toJSONString(pushMap));
			} else {
				LOG.info("极光-----------充电推送给此用户 【" + userInfo.getJpush_id() + "】");
				if (StringUtils.isNotBlank(userInfo.getJpush_id()))
					JpushUtils.pushMsgByRegId(userInfo.getJpush_id(), message, pushMap);
			}

			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return FAIL;
		}
	}
}
